// 导入请求对象
import { MyAxiosPromise, UserInfo, UserProfile } from '@/types/data'
import http from '@/utils/http'

function userInfo(): MyAxiosPromise<UserInfo> {
  return http({
    url: '/user',
    method: 'get',
  })
}

function userProfile(): MyAxiosPromise<UserProfile> {
  return http({
    url: '/user/profile',
    method: 'get',
  })
}

function editProfile(key: string, value: string) {
  return http({
    url: '/user/profile',
    method: 'patch',
    data: {
      // [key] 属性名表达式
      [key]: value,
    },
  })
}

function editPhoto(data: FormData) {
  return http({
    url: '/user/photo',
    method: 'patch',
    data,
  })
}

export { userInfo, userProfile, editProfile, editPhoto }
